public class Practice03_b {
    public static void main(String[] args) {
        //设计程序，根据学生总成绩进行排序(降序排列)，并输出学生姓名、每门课程的名称和该学生的成绩、该学生的总成绩
        String[] names = {"安琪拉", "王昭君", "蔡文姬", "妲己", "张良"};
        String[] courses = {"C++", "Java", "Python"};
        int[][] scores = {
                {90, 89, 75},
                {59, 40, 100},
                {100, 99, 80},
                {80, 61, 61},
                {60, 100, 99},
        };
        int[] total = new int[5];
        for (int i = 0; i < scores.length; i++) {
            int sum = 0;
            for (int j = 0; j < scores[i].length; j++) {
                sum += scores[i][j];
                total[i] = sum;
            }
            System.out.println(names[i] + "的总成绩为：" + sum);
        }
        for (int i = 0; i < total.length - 1; i++) {
            for (int j = 0; j < total.length - 1 - i; j++) {
                if (total[j] < total[j + 1]) {
                    //总成绩交换
                    int temp = total[j + 1];
                    total[j + 1] = total[j];
                    total[j] = temp;
                    //将名字进行交换
                    String temp1 = names[j];
                    names[j] = names[j + 1];
                    names[j + 1] = temp1;
                    //将各科成绩进行交换
                    int[] temp2 = scores[j];
                    scores[j] = scores[j + 1];
                    scores[j + 1] = temp2;
                }
            }
        }
        System.out.println();
        System.out.println("根据学生总成绩进行排序(降序排列)");
        for (int i = 0; i < scores.length; i++) {
            System.out.print(names[i] + " => "); // 输出学生姓名
            for (int j = 0; j < scores[i].length; j++) {
                System.out.print(courses[j] + ":");// 输出课程名称
                System.out.print(scores[i][j]); // 输出课程成绩
                if (j < scores[i].length - 1) {
                    System.out.print(" , ");
                }
            }
            System.out.println();
        }
    }
}